package com.mengxuegu.springboot.config;

import com.mengxuegu.springboot.component.MyLocaleResolver;
import com.mengxuegu.springboot.interceptor.LoginHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class MyspringMvcConfigurer {
    @Bean
    public WebMvcConfigurer webMvcConfigurer(){
      return   new WebMvcConfigurer(){

            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                registry.addViewController("/").setViewName("main/login");
                registry.addViewController("/index.html").setViewName("main/login");
                registry.addViewController("/main.html").setViewName("main/index");
            }

          @Override
          public void addInterceptors(InterceptorRegistry registry) {
              registry.addInterceptor(new LoginHandlerInterceptor())
                      .addPathPatterns("/**")
                      .excludePathPatterns("/","/index.html","/login")
                      .excludePathPatterns("/css/*","/img/*","/js/*")

                      //测试上传下载
                        .excludePathPatterns("/upload").excludePathPatterns("/uploadup").excludePathPatterns("/download");


          }
      };



    }
    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocaleResolver();
    }
}
